import base from './base';
import { getAntd, getEcCom,getLabel } from './convert';
import trim from "lodash/trim";
import * as authTypes from "../constants/secondAuthType";
import * as actions from "../constants/requestActions";

export const showAuthDialog = (authType) => {
    const {globalStore} = base;
    globalStore.controlDialogVisible(authType, true);
}

export const closeAuthDialog = (authType) => {
    const {globalStore} = base;
    globalStore.controlDialogVisible(authType, false);
}

export const showAuthDetail = () => {
    const {globalStore} = base;
    globalStore.controlDialogVisible(authTypes.AUTH_DETAIL_DIALOG, true);
}

export const closeAuthDetail = () => {
    globalStore.controlDialogVisible(authTypes.AUTH_DETAIL_DIALOG, false);
}

export const filterRequestAction = (submitFuncParams, submitParam, authActions) => {
    let filterResult = false;
    const authActionset = new Set([...authActions]);
    const {src, actiontype} = submitFuncParams;
    if (actiontype == "requestOperation") {
        if (src == "submit") {
            const {secondAuthStore} = base;
            const {isSubmitDirect} = secondAuthStore;
            if (isSubmitDirect == 1) {      //提交至退回节点
                if (authActionset.has(actions.REQUEST_SUBMIT_BACK_NODE)) {
                    filterResult = true;
                }
            } else {        //提交/批准
                if (authActionset.has(actions.REQUEST_APPROVAL)) {
                    filterResult = true;
                }
            }
        } else if (src == "save" && authActionset.has(actions.REQUEST_SAVE)) {     //保存
            filterResult = true;
        } else if (src == "reject" && authActionset.has(actions.REQUEST_REJECT)) {       //退回
            filterResult = true;
        }
    } else if (actiontype == "remarkOperation") {
        if (src == "save") {        //批注
            const {isremark, takisremark} = submitParam;
            if (isremark == 1) {
                if (takisremark == 2) {       //意见征询批注
                    if (authActionset.has(actions.REQUEST_TPOSTIL)) {
                        filterResult = true;
                    }
                } else {     //转发批注
                    if (authActionset.has(actions.REQUEST_POSTIL)) {
                        filterResult = true;
                    }
                }
            } else if (isremark == 9) {        //抄送批注
                if (authActionset.has(actions.REQUEST_RPOSTIL)) {
                    filterResult = true;
                }
            }
        }
    }

    return filterResult;
}


export const filterRequest4Forward = (submitFuncParams, submitParam, authActions) => {
    let filterResult = false;
    const authActionset = new Set([...authActions]);
    const {forwardflag} = submitFuncParams;
    if (forwardflag == "1") {     //转发
        if (authActionset.has(actions.REQUEST_FORWARD)) {
            filterResult = true;
        }
    } else if (forwardflag == "2") {       //意见征询
        if (authActionset.has(actions.REQUEST_TAKING_OPINIONS)) {
            filterResult = true;
        }
    } else if (forwardflag == "3") {
        if (authActionset.has(actions.REQUEST_HANDLE_FORWARD)) {      //转办
            filterResult = true;
        }
    }
    return filterResult;
}